<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of productive_lines_controller
 *
 * @author wilavel
 */
class FinalProductiveLinesController extends AppController {

    //put your code here
    var $name = "FinalProductiveLines";

    function index($final_evaluation_id) {
        $this->layout="ajax";
        $this->FinalProductiveLine->recursive = 1;
        $this->set('final_evaluation_id', $final_evaluation_id);
        $this->set('lineas', $this->FinalProductiveLine->find('all', array('conditions' => array('FinalProductiveLine.final_evaluation_id' => $final_evaluation_id), 'fields' => array('FinalProductiveLine.*', 'ProductiveActivity.nombre'))));
    }

   

    function add($final_evaluation_id) {
        $this->set('final_evaluation_id', $final_evaluation_id);
        $this->set('productiveActivities', $this->FinalProductiveLine->ProductiveActivity->find('list', array('fields' => array('ProductiveActivity.id', 'ProductiveActivity.nombre'))));
        if (!empty($this->data)) {
            if ($this->FinalProductiveLine->saveAll($this->data)) {
                $this->Session->setFlash('Registro guardado con éxito','flash_custom');
                $this->redirect(array('controller' => 'FinalProductiveLines', 'action' => 'index', $final_evaluation_id));
            }
        }
    }

    function edit($line_id) {
        $this->layout="ajax";
        $this->FinalProductiveLine->ProductiveActivity->recursive=-1;
        $this->FinalProductiveLine->recursive = -1;
        $this->set('productiveActivities', $this->FinalProductiveLine->ProductiveActivity->find('list', array('fields' => array('ProductiveActivity.id', 'ProductiveActivity.nombre'))));


        if (empty($this->data)) {
            
            $this->data = $this->FinalProductiveLine->find('first', array('conditions' => array('FinalProductiveLine.id' => $line_id)));
        } else {
            if ($this->FinalProductiveLine->saveAll($this->data)) {
                $this->Session->setFlash('Registro editado con éxito','flash_custom');
                $this->redirect(array('controller' => 'FinalProductiveLines', 'action' => 'index', $this->data['FinalProductiveLine']['final_evaluation_id']));
            }
        }
    }

    function delete($line_id, $evaluation_id) {
        if ($this->FinalProductiveLine->delete($line_id)) {
            $this->Session->setFlash('Registro editado con éxito','flash_custom');
            $this->redirect(array('controller' => 'FinalProductiveLines', 'action' => 'index', $evaluation_id));
        }
    }

    

}

?>
